#include "Scene.h"
#include "Procedural.h"
#include "MovableText.h"
using namespace Ogre;

CScene::CScene(void)
{
}

CScene::~CScene(void)
{
	// I'm sure I need to be deleting some things, but I'm not 
	// that familiar with Ogre memory management, yet.
}

//
// Name :         CScene::CreateScene(Ogre::SceneManager *pSceneManager)
// Description :  Create an Ogre scene.  I'm creating a simple scene with
//                a robot and a ninja. Both start walking.
//

void CScene::CreateScene(Ogre::SceneManager *mSceneManager)
{
	this->mSceneManager=mSceneManager;
	/*
	SceneNode* pNode = mSceneManager->getRootSceneNode()->createChildSceneNode();

	Ogre::SeriesOfTubes* mTubes = new Ogre::SeriesOfTubes(mSceneManager,16,1.0,12,12,1.0);

	mTubes->addPoint(Vector3(0,0,0));
	mTubes->addPoint(Vector3(100,0,200));
	mTubes->addPoint(Vector3(0,200,400));
	mTubes->addPoint(Vector3(50,340,300));
	mTubes->addPoint(Vector3(500,340,200));
	mTubes->addPoint(Vector3(400,100,100));
	mTubes->addPoint(Vector3(50,-20,10));
	mTubes->addPoint(Vector3(0,-100,-300));

	mTubes->setSceneNode(pNode);
	mTubes->createTubes("MyTubes","Examples/Rockwall");  

		*/

	
	// Setup Procedural root (crappy init method, have to find another one)
	Procedural::Root::getInstance()->sceneManager =mSceneManager;
	// Test primitive generation
	

   

	Procedural::CylinderGenerator().setHeight(10.f).setRadius(1.f).setUTile(3.).realizeMesh("cylinderMesh");
	putMesh("cylinderMesh", Vector3(10,10,0));


	Procedural::TunnelGenerator tunnel;
	tunnel.addpoint(Ogre::Vector3(0,0,0));
	tunnel.addpoint(Ogre::Vector3(0,10,0));
	tunnel.addpoint(Ogre::Vector3(15,20,20));
	tunnel.addpoint(Ogre::Vector3(30,30,30));
	tunnel.close();

	

	  Ogre::SceneNode* node=Procedural::TunnelGenerator().createTunnel("tunnel",Ogre::Vector3(20,0,0),Ogre::Vector3(0,12,0));
		
	
	

		Procedural::BoxGenerator().setSizeX(1).setSizeY(1).setSizeZ(1).realizeMesh("boxMesh2");
		putMesh("boxMesh2",Vector3(0,0,20));

	
		
		

		//x axis
/*
		Ogre::ManualObject *axis=new Ogre::ManualObject("Axis");
		axis->begin("BaseBlue", Ogre::RenderOperation::OT_LINE_LIST);
		axis->position(100,0,0);
		axis->position(-100,0,0);

		axis->position(0,100,0);
		axis->position(0,-100,0);

		axis->position(0,0,100);
		axis->position(0,0,-100);

		axis->end();

		mSceneManager->getRootSceneNode()->attachObject(axis);

*/


		Ogre::MovableText* msg = new Ogre::MovableText("TXT_001", "X Axis"); 
		msg->setTextAlignment(MovableText::H_CENTER, MovableText::V_ABOVE); // Center horizontally and display above the node 
		//msg->setAdditionalHeight( 2.0f ); //msg->setAdditionalHeight( ei.getRadius() ) 
		
		SceneNode *mMovableTextNode1=mSceneManager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(100,0,0));
		mMovableTextNode1->attachObject(msg);
		for(int i=10;i<=100;i=i+10)
		{
			Ogre::StringConverter *intToString;
			Ogre::String strNum=intToString->toString(i);
			Ogre::MovableText *msgX=new MovableText('X'+strNum,"X +"+strNum);
			Ogre::MovableText *msgY=new MovableText('Y'+strNum,"Y +"+strNum);
			Ogre::MovableText *msgZ=new MovableText('Y'+strNum,"Z +"+strNum);
			Ogre::MovableText *msg_X=new MovableText('X'+strNum,"X -"+strNum);
			Ogre::MovableText *msg_Y=new MovableText('Y'+strNum,"Y -"+strNum);
			Ogre::MovableText *msg_Z=new MovableText('Y'+strNum,"Z -"+strNum);
			mSceneManager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(i,0,0))->attachObject(msgX);
			mSceneManager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,i,0))->attachObject(msgY);
			mSceneManager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,i))->attachObject(msgZ);
			mSceneManager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(-i,0,0))->attachObject(msg_X);
			mSceneManager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,-i,0))->attachObject(msg_Y);
			mSceneManager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,-i))->attachObject(msg_Z);


		}


	
}

//
// Name :         CScene::frameStarted(const FrameEvent& evt)
// Description :  The callback function to indicate a new frame is started.
//

bool CScene::frameStarted(const FrameEvent& evt)
{
	

	return true;
}

void CScene::putMesh(const std::string& meshName, const Vector3& position)
{
	Ogre::Entity* ent2 = mSceneManager->createEntity(meshName);
	SceneNode* sn = mSceneManager->getRootSceneNode()->createChildSceneNode();
	sn->attachObject(ent2);
	sn->setPosition(position);
	ent2->setMaterialName("BaseWhiteNoLighting");
}
